﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;

namespace employee.Controls
{
    public partial class emLeaveDetail : common.controls.baseUserControl
    {
        public emLeaveDetail()
        {
            InitializeComponent();
            leaveTypeCb.SelectFirstIfNull();
            planDateEd.ForeColor = common.Settings.myTheme.Info.ForeColor;
            planDateEd.BackColor = common.Settings.myTheme.Info.BackColor;
        }

        public void ReLoad()
        {
            UpdatePlanRestartDate();
        }

        public void SetDataSource(BindingSource dataSrc)
        {
            common.BindingLibs.BindObject(this.frDateEd,dataSrc, DataAccess.DataCache.myBaseDS.emLeave.frDateColumn.ColumnName);
            common.BindingLibs.BindObject(this.durationEd, dataSrc, DataAccess.DataCache.myBaseDS.emLeave.durationColumn.ColumnName);
            common.BindingLibs.BindObject(this.restartDateEd, dataSrc, DataAccess.DataCache.myBaseDS.emLeave.reStartDateColumn.ColumnName);
            common.BindingLibs.BindObject(this.leaveTypeCb, dataSrc, DataAccess.DataCache.myBaseDS.emLeave.typeColumn.ColumnName);
            common.BindingLibs.BindObject(this.noteEd, dataSrc, DataAccess.DataCache.myBaseDS.emLeave.notesColumn.ColumnName);

            noteEd.MaxLength = DataAccess.DataCache.myBaseDS.emLeave.notesColumn.MaxLength;
        }

        public virtual void Init() 
        {
            leaveTypeCb.LoadData();
        }

        public virtual bool CheckData()
        {
            bool retVal = true;
            ClearNotifyError();
            //if (frDateEd.myValue == common.Consts.constNullDate) 
            //{
            //    NotifyError(frDateLbl);
            //    retVal = false;
            //}
            //if (leaveTypeCb.myValue == "") 
            //{
            //    NotifyError(leaveTypeLbl);
            //    retVal = false;
            //}
            return retVal;
        }
        public virtual void LockEdit(bool state)
        {
            state = !state;
            frDateEd.Enabled = state;
            durationEd.Enabled = state;
            restartDateEd.Enabled = state;
            leaveTypeCb.Enabled = state;
            noteEd.Enabled = state;
        }
        public virtual void SetFocus()
        {
            this.Focus();
            frDateEd.Focus();
        }
        private void UpdatePlanRestartDate()
        {
            if (frDateEd.myValue==common.Consts.constNullDate)
            {
                planDateEd.myValue = common.Consts.constNullDate;
                return;
            }
            planDateEd.myValue = frDateEd.myValue.AddDays((int)durationEd.Value);
        }

        private void durationEd_ValueChanged(object sender, EventArgs e)
        {
            UpdatePlanRestartDate();
        }

        private void frDateEd_Validated(object sender, EventArgs e)
        {
            UpdatePlanRestartDate();
        }
    }
}
